<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/23
 * Time: 16:23
 */

namespace App\Game\Traits;


trait IbcTrait
{
    public function apiDataParse(array $apiData, array $data)
    {
        $data = $this->statusParse($apiData, $data);
        $data = $this->gameCodeParse($apiData, $data);
        return $data;
    }

    private function statusParse(array $apiData, array $data)
    {
        if (array_key_exists('TicketStatus', $apiData)) {
            switch ($apiData['TicketStatus']) {
                case 'Waiting':
                    $data['status'] = 0;
                    break;
                case 'running':
                    $data['status'] = 0;
                    break;
                case 'WON':
                    $data['status'] = 1;
                    break;
                case 'LOSE':
                    $data['status'] = 1;
                    break;
                case 'Draw':
                    $data['status'] = 1;
                    break;
                case 'Reject':
                    $data['status'] = -1;
                    break;
                case 'Refund':
                    $data['status'] = -1;
                    break;
                case 'Void':
                    $data['status'] = -1;
                    break;
                case 'Half Won':
                    $data['status'] = 1;
                    break;
                case 'Half Lose':
                    $data['status'] = 1;
                    break;
                default:
                    $data['status'] = 0;
                    break;
            }
        }
        return $data;
    }


    private function gameCodeParse(array $apiData, array $data)
    {
        if (array_key_exists('SportType', $apiData)) {
            switch ($apiData['SportType']) {
                case null:
                    $data['game_code'] = 'cgtz';
                    break;
                default:
                    $data['game_code'] = $apiData['SportType'];
                    break;
            }
        }
        return $data;
    }


}